package day06Case01;

import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/6
 */
public class getEvenNumber {
    /**
     *      需求：
     *          求任意两个数之间的偶数和，并返回。
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个整数：");
        int num1 = sc.nextInt();
        System.out.println("请输入第二个整数：");
        int num2 = sc.nextInt();
        int sum = getevenNumber(num1, num2);
        System.out.println("sum:" + sum);
    }

    public static int getevenNumber(int num1, int num2) {
        int sum = 0;
        if (num1 == num2) {
            if (num1 % 2 == 0) {
                sum = num1;
            }
        } else {
            if (num1 > num2) {
                int temp = num1;
                num1 = num2;
                num2 = temp;
            }
            for (int i = num1; i <= num2; i++) {
                if (i % 2 == 0) {
                    sum += i;
                }
            }
        }
        return sum;
    }
}
